using System;
using System.Collections.Generic;
using System.Text;
using HeThongDAO;
using NUnit.Framework;
using System.Data;
using DTO;

namespace _041346_1041351_1041352_UnitTest
{
    [TestFixture]
    public class TestPhieuNhap
    {
        [Test]
        public void TestThemPhieuNhap()
        {
            DataTable dt = HeThongDAO.PhieuNhapDAO.DocSchema("SELECT * FROM PHIEU_NHAP");
            DataRow dr = dt.NewRow();
            dr["MaPhieuNhap"] = 12;
            dr["NgayNhap"] = DateTime.ParseExact("05/28/2011", "MM/dd/yyyy", null);

            PhieuNhapDTO DTO = new PhieuNhapDTO();
            DTO.IMaPhieuNhap = 12;
            DTO.INgayNhap = DateTime.ParseExact("05/28/2011", "MM/dd/yyyy", null);
            PhieuNhapDAO.ThemPhieuNhap(DTO);
            DataTable dt_test = PhieuNhapDAO.LayTatCaPhieuNhap();
            DataRow dr_test = dt_test.Rows[dt_test.Rows.Count - 1];

            Assert.AreEqual(dr["MaPhieuNhap"], dr_test["MaPhieuNhap"]);
            Assert.AreEqual(dr["NgayNhap"], dr_test["NgayNhap"]);

            dt = HeThongDAO.ChiTietPhieuNhapDAO.DocSchema("SELECT * FROM CHI_TIET_PHIEU_NHAP");
            DataRow dr1 = dt.NewRow();
            dr1["MaChiTietPhieuNhap"] = 12;
            dr1["MaPhieuNhap"] = 2;
            dr1["SoLuong"] = 100;
            dr1["DonGiaNhap"] = 20000;
            dr1["MaSach"] = 3;

            DataRow dr2 = dt.NewRow();
            dr2["MaChiTietPhieuNhap"] = 13;
            dr2["MaPhieuNhap"] = 2;
            dr2["SoLuong"] = 2000;
            dr2["DonGiaNhap"] = 30000;
            dr2["MaSach"] = 5;

            ChiTietPhieuNhapDTO ChiTietDTO1 = new ChiTietPhieuNhapDTO();
            ChiTietDTO1.IDonGia = 20000;
            ChiTietDTO1.IMaChiTietPhieuNhap = 12;
            ChiTietDTO1.IMaPhieuNhap = 2;
            ChiTietDTO1.IMaSach = 3;
            ChiTietDTO1.ISoLuong = 100;
            ChiTietPhieuNhapDAO.ThemChiTietPhieuNhap(ChiTietDTO1);
            dt_test = HeThongDAO.ChiTietPhieuNhapDAO.LayTatCaChiTietPhieuNhap();
            dr_test = dt_test.Rows[dt_test.Rows.Count - 1];

            Assert.AreEqual(dr1["MaPhieuNhap"], dr_test["MaPhieuNhap"]);
            Assert.AreEqual(dr1["MaChiTietPhieuNhap"], dr_test["MaChiTietPhieuNhap"]);
            Assert.AreEqual(dr1["SoLuong"], dr_test["SoLuong"]);
            Assert.AreEqual(dr1["DonGiaNhap"], dr_test["DonGiaNhap"]);
            Assert.AreEqual(dr1["MaSach"], dr_test["MaSach"]);

            ChiTietPhieuNhapDTO ChiTietDTO2 = new ChiTietPhieuNhapDTO();
            ChiTietDTO2.IDonGia = 30000;
            ChiTietDTO2.IMaChiTietPhieuNhap = 13;
            ChiTietDTO2.IMaPhieuNhap = 2;
            ChiTietDTO2.IMaSach = 5;
            ChiTietDTO2.ISoLuong = 2000;
            ChiTietPhieuNhapDAO.ThemChiTietPhieuNhap(ChiTietDTO2);
            dt_test = HeThongDAO.ChiTietPhieuNhapDAO.LayTatCaChiTietPhieuNhap();
            dr_test = dt_test.Rows[dt_test.Rows.Count - 1];

            Assert.AreEqual(dr2["MaPhieuNhap"], dr_test["MaPhieuNhap"]);
            Assert.AreEqual(dr2["MaChiTietPhieuNhap"], dr_test["MaChiTietPhieuNhap"]);
            Assert.AreEqual(dr2["SoLuong"], dr_test["SoLuong"]);
            Assert.AreEqual(dr2["DonGiaNhap"], dr_test["DonGiaNhap"]);
            Assert.AreEqual(dr2["MaSach"], dr_test["MaSach"]);
        }
    }
}
